/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package reciprocal;

/**
 *
 * @author Eagle
 */
public class Main {

    /**
     * @param args the command line arguments
     */


    public static void main(String[] args) {
        // TODO code application logic here

        int qGrpN,tGrpN,dGrpN,gluConnN,gabaConnN;
        double ggRatio;

        int totalCellN, totalSlotN;
        boolean cellIsGlu[];
        int gluCellN,gabaCellN;
        int[] slotShuffleStack;
        int[] pairStack;
        int[] summary;
        int[][] writeBuffer;

        qGrpN=52;
        tGrpN=51;
        dGrpN=14;

        gluConnN=69;
        gabaConnN=126;
        ggRatio=0.19;
        
        int cycles=100000;

        totalCellN=qGrpN*4+tGrpN*3+dGrpN*2;
        totalSlotN=qGrpN*12+tGrpN*6+dGrpN*2;

        gabaCellN=(int)Math.round(ggRatio*totalCellN);
        gluCellN=totalCellN-gabaCellN;

        writeBuffer=new int[cycles][5];

        ////////////////////////////////////////////////////////////
        //////////the above part should be fine running once////////
        ////////////////////////////////////////////////////////////
        
        ////////////////////////////////////////////////////////////
        //////////start of larger cycle/////////////////////////////
        ////////////////////////////////////////////////////////////

        for (int currCycle=0;currCycle<cycles;currCycle++)
        {
            summary=new int[5];//[blank][oneGlu][twoGlu][oneGABA][twoGABA][onePlusOne]

            int currGluConnN=gluConnN;
            int currGabaConnN=gabaConnN;

            cellIsGlu=new boolean[totalCellN];

            for (int i=0;i<gluCellN;i++) cellIsGlu[i]=true;
            for (int i=gluCellN;i<totalCellN;i++) cellIsGlu[i]=false;

            slotShuffleStack=new int[totalSlotN];

            pairStack=new int[totalSlotN/2] ;

            //for (int i=0;i<totalCellN;i++) cellShuffleStack[i]=i;
            for (int i=0;i<totalSlotN;i++) slotShuffleStack[i]=i;

            myCommonTask.shuffleArray(cellIsGlu);
            myCommonTask.shuffleArray(slotShuffleStack);
            for (int i=0;(currGluConnN+currGabaConnN)>0;i++)
            {
                int currSlot=slotShuffleStack[i];
    //            System.out.println(currSlot);
                int currPreCell=myCommonTask.connInfo(currSlot, qGrpN, tGrpN, dGrpN)[1];
                if (cellIsGlu[currPreCell]&&currGluConnN>0)
                {
                    mySum.sum(currSlot,true,pairStack,summary);
                    currGluConnN--;
                }
                else if (!cellIsGlu[currPreCell]&&currGabaConnN>0)
                {
                    mySum.sum(currSlot,false,pairStack,summary);
                    currGabaConnN--;
                }
            }
            System.arraycopy(summary, 0, writeBuffer[currCycle], 0, 5);
        }
        myFile.saveFile(writeBuffer,"1Glu,2Glu,1GABA,2GABA,1Each\n");
    }
    ////////////////////////////////////////////////////
    //Other  Fucntions//////////////////////////////////
    ////////////////////////////////////////////////////
}
